//
//  MainViewController.m
//  cc
//
//  Created by ZLQ on 2016/10/24.
//  Copyright © 2016年 hbyj. All rights reserved.
//

#import "MainViewController.h"
#import "MainNaviViewController.h"
#import "OneViewController.h"
#import "TwoViewController.h"
@interface MainViewController ()

@end

@implementation MainViewController
+ (void)initialize
{
    if (self == [MainViewController class]) {
        UITabBarItem *item = [UITabBarItem appearance];
        NSDictionary *normalDict = @{NSBackgroundColorAttributeName:RGBColor(1, 225, 247),NSForegroundColorAttributeName:RGBColor(132, 132, 132),NSFontAttributeName:CCFont(12)};
        [item setTitleTextAttributes:normalDict forState:UIControlStateNormal];
        NSDictionary *selectedDict = @{NSBackgroundColorAttributeName:RGBColor(205, 225, 247),NSForegroundColorAttributeName:RGBColor(240, 0, 16),NSFontAttributeName:CCFont(15)};
        [item setTitleTextAttributes:selectedDict forState:UIControlStateSelected];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addViewControllers];
}

-(void)addViewControllers{
    [self addChildViewController:[[OneViewController alloc] init] AndTitle:@"demo1" AndImageName:@"find_gry" AndSelectedImageName:@"find_red"];
    [self addChildViewController:[[TwoViewController alloc] init] AndTitle:@"demo2" AndImageName:@"more_gry" AndSelectedImageName:@"more_red"];
}

-(void)addChildViewController:(UIViewController *)childController AndTitle:(NSString *)title AndImageName:(NSString *)imageName AndSelectedImageName:(NSString *)selectedImageName{
    MainNaviViewController *naV = [[MainNaviViewController alloc] initWithRootViewController:childController];
    naV.tabBarItem.title = title;
    
    childController.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childController.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self addChildViewController:naV];
    
    //设置Controller的navigationBar背景颜色
    naV.navigationBar.barTintColor = RGBColor(222, 224, 226);
    
    if ([title isEqualToString:@"demo1"]) {
        //UIImage *findImage = [UIImage imageNamed:@"醉字"];
        //UIImageView *imageview = [[UIImageView alloc] initWithImage:findImage];
        //childController.navigationItem.titleView = imageview;
    }else if([title isEqualToString:@"demo2"]){
        //UIImage *moreImage = [UIImage imageNamed:@"轩字"];
        //UIImageView *imageview = [[UIImageView alloc] initWithImage:moreImage];
        //childController.navigationItem.titleView = imageview;
    }else if ([title isEqualToString:@"更多"]){
        
    }
    /*
     //[UIFont fontWithName:@"Helvetica-Bold"size:20] 加粗
     NSDictionary *dict = @{NSFontAttributeName:[UIFont fontWithName:@"Helvetica-Bold"size:20],NSForegroundColorAttributeName:HLColor(255, 255, 255, 1)};
     naV.navigationBar.titleTextAttributes =  dict;
     */
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
